package com.iqiyi.config;

import com.iqiyi.interceptor.JWTInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * TODO
 *
 * @author qihangtao
 * @date 2021/1/6 0006 11:54
 */
@Configuration
public class CrossConfig implements WebMvcConfigurer {
    //创建一个拦截器的对象
    public JWTInterceptor jwtInterceptor(){

        return new JWTInterceptor();
    }
    /**
     * 注册拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册指定拦截器
        registry.addInterceptor(jwtInterceptor());
    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowCredentials(true)
                .allowedMethods("GET","POST","DELETE","PUT","PATCH","OPTIONS","HEAD")
                .maxAge(3600*24);
    }
}
